﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Utilities;
using Casanova.Web;
using Domain.DAL;
using Domain.Models;
using System.Data;

namespace WebApp.RepairingTickets
{
    public partial class RepairingTicketTemplate : System.Web.UI.Page
    {

        #region Private Properties

        public long RepairingTicketHistoryID
        {
            get
            {
                if (this.ViewState["RepairingTicketHistoryID"] != null)
                {
                    return Convert.ToInt64(this.ViewState["RepairingTicketHistoryID"]);
                }
                return MyConfig.NullNumber;
            }
            set
            {
                this.ViewState["RepairingTicketHistoryID"] = value.ToString();
            }
        }

        #endregion

        #region Event Handlers

        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (!IsPostBack)
                {
                    GetParam();
                    if (this.RepairingTicketHistoryID != MyConfig.NullNumber)
                    {
                        LoadForm();
                    }
                }
            }
            catch (Exception ex)
            {
                Utility.ShowMessageBox(this.Page, ex.ToString());
            }
        }

        #endregion

        #region Private Methods

        private void LoadForm()
        {
            try
            {
                RepairingTicketDAO rtDAO = RepairingTicketDAO.GetInstance();
                DataSet ds = new DataSet();
                ds = rtDAO.GetForPrintTemplate(string.Empty);

                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    if (ds.Tables[0].Rows[0]["FullName"] != null && ds.Tables[0].Rows[0]["FullName"] != DBNull.Value)
                    {
                        lblFullName.Text = ds.Tables[0].Rows[0]["FullName"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["Mobile"] != null && ds.Tables[0].Rows[0]["Mobile"] != DBNull.Value)
                    {
                        lblMobile.Text = ds.Tables[0].Rows[0]["Mobile"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["Address"] != null && ds.Tables[0].Rows[0]["Address"] != DBNull.Value)
                    {
                        lblAddress.Text = ds.Tables[0].Rows[0]["Address"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["RepairingTypeName"] != null && ds.Tables[0].Rows[0]["RepairingTypeName"] != DBNull.Value)
                    {
                        lblRepairingTypeName.Text = ds.Tables[0].Rows[0]["RepairingTypeName"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["ProductTypeName"] != null && ds.Tables[0].Rows[0]["ProductTypeName"] != DBNull.Value)
                    {
                        lblProductTypeName.Text = ds.Tables[0].Rows[0]["ProductTypeName"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["Manufacturer"] != null && ds.Tables[0].Rows[0]["Manufacturer"] != DBNull.Value)
                    {
                        lblManufacturer.Text = ds.Tables[0].Rows[0]["Manufacturer"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["Model"] != null && ds.Tables[0].Rows[0]["Model"] != DBNull.Value)
                    {
                        lblModel.Text = ds.Tables[0].Rows[0]["Model"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["SerialNumber"] != null && ds.Tables[0].Rows[0]["SerialNumber"] != DBNull.Value)
                    {
                        lblSerialNumber.Text = ds.Tables[0].Rows[0]["SerialNumber"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["ProductDescription"] != null && ds.Tables[0].Rows[0]["ProductDescription"] != DBNull.Value)
                    {
                        lblProductDescription.Text = ds.Tables[0].Rows[0]["ProductDescription"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["Note"] != null && ds.Tables[0].Rows[0]["Note"] != DBNull.Value)
                    {
                        lblNote.Text = ds.Tables[0].Rows[0]["Note"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["Repairer"] != null && ds.Tables[0].Rows[0]["Repairer"] != DBNull.Value)
                    {
                        lblRepairer.Text = ds.Tables[0].Rows[0]["Repairer"].ToString();
                    }
                    if (ds.Tables[0].Rows[0]["CreatedDateForRepairing"] != null && ds.Tables[0].Rows[0]["CreatedDateForRepairing"] != DBNull.Value)
                    {
                        lblCreatedDateForRepairing.Text = ds.Tables[0].Rows[0]["CreatedDateForRepairing"].ToString();
                    }
                }
            }
            catch (Exception)
            {
                throw;
            }
        }

        private void GetParam()
        {
            this.RepairingTicketHistoryID = QueryStringUtility.GetInt64("RepairingTicketHistoryID", MyConfig.NullNumber);
        }

        #endregion
    }
}